package com.learn.design.strategy;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.learn.design.strategy.example.CommonPairResponse;
import com.learn.design.strategy.example.FormServiceImpl;
import com.learn.design.strategy.example.FormSubmitRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.Map;

/**
 * @author Administrator
 */
@RestController
@SpringBootApplication
public class Starter {
    public static void main(String[] args) {
        SpringApplication.run(Starter.class, args);
    }


    @Autowired
    private FormServiceImpl formService;

    @PostMapping("/form/submit")
    public CommonPairResponse<String, Serializable> submitForm(@RequestParam String submitType, @RequestParam String formInputJson) {
//    public CommonPairResponse<String, Serializable> submitForm(@RequestBody Map<Object,Object> param) {
//        String submitType = (String) param.get("submitType");
//        String formInputJson = (String) param.get("formInputJson");
        JSONObject formInput = JSON.parseObject(formInputJson);

        FormSubmitRequest request = new FormSubmitRequest();
        request.setUserId(123456L);
        request.setSubmitType(submitType);
        request.setFormInput(formInput);

        return formService.submitForm(request);
    }

}
